---
title: DEFIFD Crowdfund DApp (Sepolia Version)
runtime: shiny
output: html_document
---

```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE) 
```

```{r}
library(shiny)
library(httr)
library(jsonlite)
```

\

##### Want to contribute? 
- Send SepoliaETH to `0x368113c092e11F08478a63B778B88590563864BC` \ 
- If you don't already have an Ethereum-enabled wallet, you can download the MetaMask browser extension at <a href="https://metamask.io/download/">https://metamask.io/download/</a> \

##### In return, you'll receive:
- 1 newly minted DEFIFD for every 0.01 SepoliaETH you contribute. \ 
- Note: you'll receive fractional amounts of DEFIFD for smaller contributions, at a `10:1` (DEFIFD:SepoliaETH) ratio
\
\
\

```{r}

textInput(
  inputId = "address",
  label = "Enter Account Address:",
  value = ""
)

renderTable({
  #Enter your own Etherscan API key and contract account address below
  key = "A8BJXUUI2TPD4WKP9UKTGSNWBEEYVFPX9K"
  contract = "0x368113c092e11F08478a63B778B88590563864BC"
  user = input$address
        
  #Get DEFIFD balance of user account (user_DEFIFD)
  sub1 = "https://api-sepolia.etherscan.io/api?module=account&action=tokenbalance&contractaddress="
  sub2 = "&address="
  sub3 = "&tag=latest&apikey="

  link = paste(sub1, contract, sub2, user, sub3, key, sep="")
  res = fromJSON(rawToChar(GET(link)$content))
  user_DEFIFD = as.numeric(res$result) / 10^18
  
  rm(sub1, sub2, sub3, link, res)
  #---------------------------------------------------
  
  #Get total DEFIFD  token supply (supply_DEFIFD)
  sub1 = "https://api-sepolia.etherscan.io/api?module=stats&action=tokensupply&contractaddress="
  sub2 = "&apikey="
  link = paste(sub1, contract, sub2, key, sep="")

  res = fromJSON(rawToChar(GET(link)$content))
  supply_DEFIFD = as.numeric(res$result) / 10^18
        
  rm(sub1, sub2, link, res)
  #---------------------------------------------------

  #create output
  row1 = c(round(user_DEFIFD, 4), " DEFIFD")
  row2 = c(round(user_DEFIFD/supply_DEFIFD*100, 4), "% of Total DEFIFD Supply")
  blanks = c("", "")

  table = rbind(row1, row2, blanks)
  colnames(table) = c(" ", "  ")
  output = table
})
```

##### Overall project information:
```{r}

renderTable({
  #Enter your own Etherscan API key and contract account address below
  key = "A8BJXUUI2TPD4WKP9UKTGSNWBEEYVFPX9K"
  contract = "0x368113c092e11F08478a63B778B88590563864BC"
  
  #Get total DEFIFD  token supply (supply_DEFIFD)
  sub1 = "https://api-sepolia.etherscan.io/api?module=stats&action=tokensupply&contractaddress="
  sub2 = "&apikey="
  link = paste(sub1, contract, sub2, key, sep="")

  res = fromJSON(rawToChar(GET(link)$content))
  supply_DEFIFD = as.numeric(res$result) / 10^18
        
  rm(sub1, sub2, link, res)
  #---------------------------------------------------
        
  #Get ETH balance of contract account (contract_ETH)
  sub1 = "https://api-sepolia.etherscan.io/api?module=account&action=balance&address="
  sub2 = "&tag=latest&apikey="
        
  link = paste(sub1, contract, sub2, key, sep="")
  res = fromJSON(rawToChar(GET(link)$content))
  contract_ETH = as.numeric(res$result) / 10^18
        
  rm(sub1, sub2, link, res)
  #---------------------------------------------------
        
  #create output
  row1 = c("Total Circulating Supply: ", round(supply_DEFIFD, 4), " DEFIFD")
  row2 = c("Total Funds Raised: ", round(contract_ETH, 4), " SepoliaETH")
  blanks = c("", "", "")

  table = rbind(row1, row2, blanks)
  colnames(table) = c(" ", "  ", "  ")
  output = table
})

```

The backend smart-contract account address is `0x368113c092e11F08478a63B778B88590563864BC` \
The originating (founder) EOA address is `0xC3Da0eaB3D30C4a6a298467729B00F659daDA0BC` \
\
** This dApp is powered by Etherscan.io APIs

